#include "stdafx.h"
#include "Controller.h"

#include "Model.h"
#include "EventManagerSngl.h"
#include "PersistenceController.h"

#include <db/RecordBase.h>
#include <db/SqliteInitInfo.h>

#ifdef WIN32
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif //_DEBUG
#endif //WIND32

namespace serika
{
	namespace dq
	{
		Controller::Controller()
		{
		}

		Controller::~Controller()
		{
		}

		void Controller::OnInitialize()
		{
			std::locale::global(std::locale(".936"));
			ModelSngl::Instance()->Initialize();
			//EvnMgrSngl::Instance();
			this->InitDb();

			this->CreateControllers();
		}

		void Controller::InitDb()
		{
			db::SqliteInitInfo info;
			info.database = "dq9";
#ifndef _DEBUG
			info.dbFile = "dq9.db";
#else
			info.dbFile = "dq9d.db";
#endif
			bool r = db::RecordBase::Initialize("sqlite", info);
			ASSERT(r);
		}

		void Controller::CreateControllers()
		{
			mPersistenceController = new PersistenceController();
		}

		void Controller::OnFinalize()
		{
			delete mPersistenceController;

			db::RecordBase::Finalize();
			ModelSngl::Instance()->Finalize();
			ModelSngl::Close();

			EventManager::Close();
		}
	}
}
